package com.example.carrierapp.ui.person;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.carrierapp.base.MVPBaseActivity;
import com.example.carrierapp.bean.home.PersonalInfoBean;
import com.example.carrierapp.ui.person.notice.NoticeActivity;
import com.example.carrierapp.ui.person.set.SettingActivity;
import com.example.carrierapp.ui.view.CircleImageView;
import com.example.carrierapp.util.ActivityUtil;
import com.example.carrierapp.util.GlideApp;
import com.example.carrierapp.util.ToastUtils;
import com.example.lb.fingerdemo.R;
import com.q42.android.scrollingimageview.ScrollingImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 个人中心
 */
public class PersonCenterActivity extends MVPBaseActivity<PersonCenterContract.View, PersonCenterPrenter> implements PersonCenterContract.View {
    @BindView(R.id.civ_person_head)
    CircleImageView mCiHead;
    @BindView(R.id.tv_person_name)
    TextView mTvName;
    @BindView(R.id.tv_person_phone)
    TextView mTvPhone;
    @BindView(R.id.btn_person_noti)
    Button mBtnNotice;
    @BindView(R.id.img_wave)
    ScrollingImageView mIvWave;


    private String mHeadUrl;

    @Override
    public int getContentView() {
        return R.layout.activity_person_center;
    }

    @Override
    public String getTitleString() {
        return "个人中心";
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        mPresenter.attachView(this);
        mPresenter.getUserInfo();
        mIvWave.start();
    }

    @Override
    public void initView() {
        super.initView();
    }

    @Override
    protected PersonCenterPrenter createPresenter() {
        return new PersonCenterPrenter(this);
    }

    @Override
    public void getUserInfoSuccess(PersonalInfoBean info) {
//        mHeadUrl = info.headPortrait;
//        GlideApp.with(this).load(info.headPortrait).placeholder(R.mipmap.img_defaultavatar).into(mCiHead);
        mTvName.setText(TextUtils.isEmpty(info.carrierName) ? "承运商" : info.carrierName);
        mTvPhone.setText(TextUtils.isEmpty(info.phone) ? "暂无电话" : info.phone);
//        if (info.noticeCount > 99) {
//            mBtnNotice.setText("99+");
//            mBtnNotice.setVisibility(View.VISIBLE);
//        } else if (info.noticeCount > 0) {
//            mBtnNotice.setText(info.noticeCount + "");
//            mBtnNotice.setVisibility(View.VISIBLE);
//        } else {
//            mBtnNotice.setVisibility(View.INVISIBLE);
//        }
    }

    @Override
    protected boolean showBottomLine() {
        return false;
    }

    @Override
    public void getUserInfoField(String msg) {
        ToastUtils.showCenterToast(this, msg);
    }

    @OnClick({R.id.tv_person_set, R.id.tv_person_noti, R.id.civ_person_head})
    public void onCLIck(View v) {
        switch (v.getId()) {
            case R.id.tv_person_set:
                ActivityUtil.startActivity(this, SettingActivity.class);
                break;
            case R.id.tv_person_noti:
                ActivityUtil.startActivity(this, NoticeActivity.class);
                break;

            case R.id.civ_person_head:
                if (!TextUtils.isEmpty(mHeadUrl))
                    ActivityUtil.startSeePhoto(this, mHeadUrl);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mIvWave.stop();
    }
}
